package com.cqust.wdm.emsboot.controller;

import com.cqust.wdm.emsboot.domain.Retake;
import com.cqust.wdm.emsboot.service.IRetakeService;
import com.cqust.wdm.emsboot.util.AjaxResult;
import com.cqust.wdm.emsboot.util.BaseController;
import com.cqust.wdm.emsboot.util.ExcelUtil;
import com.cqust.wdm.emsboot.util.page.TableDataInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 退货单Controller
 */
@RestController
@RequestMapping("/emsboot/retake")
public class RetakeController extends BaseController {
    @Autowired
    private IRetakeService retakeService;

    /**
     * 查询退货单列表
     */

    @GetMapping("/list")
    public TableDataInfo list(Retake retake) {
        startPage();
        List<Retake> list = retakeService.selectRetakeList(retake);
        return getDataTable(list);
    }

    /**
     * 导出退货单列表
     */
//
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Retake retake) {
//        List<Retake> list = retakeService.selectRetakeList(retake);
//        ExcelUtil<Retake> util = new ExcelUtil<Retake>(Retake.class);
//        util.exportExcel(response, list, "退货单数据");
//    }

    /**
     * 获取退货单详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(retakeService.selectRetakeById(id));
    }

    /**
     * 新增退货单
     */
    @ApiOperation("新增退货单")
    @PostMapping
    public AjaxResult add(@RequestBody Retake retake) {
        return toAjax(retakeService.insertRetake(retake));
    }

    /**
     * 修改退货单
     */

    @PutMapping
    public AjaxResult edit(@RequestBody Retake retake) {
        return toAjax(retakeService.updateRetake(retake));
    }

    /**
     * 删除退货单
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(retakeService.deleteRetakeByIds(ids));
    }
}
